package com.ruoyi.ai.controller;

import com.ruoyi.ai.domain.StreamParamVO;
import com.ruoyi.ai.service.IChatGtpService;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

/**
 * @description:SSEStreamController
 * @author: caoes
 * create:2023/6/30 15:15
 **/

@Api(tags = "chatgpt sse流相关接口")
@RestController
@RequestMapping("ai/sse/stream")
public class SSEStreamController {

    @Autowired
    private IChatGtpService iChatGtpService;

    @ApiOperation(value = "chatBot", notes = "chatgpt消息发送")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "streamParamVO", value = "对话内容", required = true, dataTypeClass = StreamParamVO.class),
    })
    @PostMapping(value = "chatBot")
    public void chatBot(@RequestBody StreamParamVO streamParamVO, HttpServletResponse response) {
        // 校验内容是否敏感词汇
        if (StringUtils.isBlank(streamParamVO.getPrompt())) {
            throw new RuntimeException("请输入内容");
        }
        iChatGtpService.chatBotSseStream(streamParamVO, response);
    }
}
